package thread.homework.problem1;

public class ZiMu extends Thread {
    private Flag flag;
    private int count = 65;

    public ZiMu(Flag flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (flag) {
                if (count == 91)
                    return;
                if (!flag.isFlag()) {
                    try {
                        flag.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println((char) count);
                count++;
                flag.setFlag(false);
                flag.notify();
            }
        }
    }
}
